package com.example.service;

import cn.hutool.core.io.FileUtil;
import com.example.common.AjaxJson;
import org.springframework.stereotype.Service;

import java.io.File;

//我叫蔡文红
@Service
public class CutFolderService {

    public AjaxJson cutFolder(String srcFolder, String srcNameSplit, String targetFolder) {
        AjaxJson ajaxJson = new AjaxJson();
        if (srcFolder == null || "".equals(srcFolder)) {
            return AjaxJson.returnExceptionInfo("【源文件夹路径】不能为空");
        }
        if (srcNameSplit == null || "".equals(srcNameSplit)) {
            return AjaxJson.returnExceptionInfo("【源文件名称】不能为空");
        }
        if (targetFolder == null || "".equals(targetFolder)) {
            return AjaxJson.returnExceptionInfo("【目标文件夹路径】不能为空");
        }
        String[] strArray = srcNameSplit.split(",");
        for (String srcName : strArray) {
            File src = FileUtil.file(srcFolder + File.separator + srcName);
            File target = FileUtil.file(targetFolder);
            FileUtil.move(src, target, false);
        }
        return ajaxJson;
    }

}
